var count = 0
window.onload = function() {

    // 退出账号
    var quit = document.getElementById("quit")
    quit.onclick = function() {
        console.log("   ")
        if (confirm('您确定要退出该账号吗?')) {
            console.log("queding")
            localStorage.removeItem("************")
            window.location.href = "z-login.html"


        }
    }
    var names = localStorage.getItem("************")
        // for (var j = 0; j < localStorage.length; j++) {
        //     console.log(
        //         'localStorage里存储的第' +
        //         j +
        //         '条数据的名字为：' +
        //         localStorage.key(j) +
        //         ',值为：' +
        //         localStorage.getItem(localStorage.key(j)));
        // }
    console.log(names)

    var btn = document.getElementById('rebtn')
    btn.onclick = function() {
        var oldp = document.getElementById('oldps').value
        var newp = document.getElementById('newp').value
        var np = document.getElementById('np').value

        // var oldp = $('#odlp').val(); //获取值
        // var newp = $('#newp').val();
        // var np = $('#np').val();

        for (let j = 0; j < localStorage.length; j++) {
            console.log(localStorage.getItem(localStorage.key(j)))
            if (localStorage.getItem(localStorage.key(j)) == names) {
                console.log("进行输入的密码是否与旧密码一致")
                count = j
                console.log("count:" + count)
                break
            }
        }
        console.log(localStorage.key(count))
        if (oldp == '' || newp == '' || np == '') {
            alert('请输入密码')

        } else {
            if (oldp != localStorage.getItem(localStorage.key(count - 1))) {
                // console.log(typeof localStorage.key(count))
                // console.log(localStorage.key(count))
                // console.log(typeof oldp)
                // console.log(oldp)
                // console.log(count)
                console.log(localStorage.getItem(localStorage.key(count)))
                alert('旧密码错误!')
            } else {
                if (oldp == newp) {
                    alert('新密码不能与旧密码一致哟!')
                } else {
                    if (newp != np) {
                        alert('新密码输入不一致!')
                    } else {
                        alert('修改密码成功,您的密码是' + newp)
                        for (var i = 0; i < document.getElementsByTagName("input").length - 1; i++) {
                            document.getElementsByTagName("input")[i].value = ""
                        }

                        localStorage.setItem(names, newp)
                        for (var j = 0; j < localStorage.length; j++) {
                            console.log(
                                'localStorage里存储的第' +
                                j +
                                '条数据的名字为：' +
                                localStorage.key(j) +
                                ',值为：' +
                                localStorage.getItem(localStorage.key(j)));
                        }
                    }
                }
            }

        }
    }

    var exit = document.getElementById('exit')
    exit.onclick = function() {
        if (confirm('您确定要退出吗?')) {
            localStorage.removeItem("************")
            window.location.href = 'z-login.html'
        }
    }


}